<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="lib/icheck/icheck.css" rel="stylesheet" type="text/css" />
<link href="lib/Hui-iconfont/1.0.6/iconfont.css" rel="stylesheet" type="text/css" />
<link href="lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="lib/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<style>
.rule-con{margin:10px 0px 30px 20px;}
.mleft{margin-left:-150px;}
.wimg{margin-left:20px;margin-top:-55px;height:90px;border:0px solid white;}
.bor{width:820px;height:20px;border-bottom:1px solid #ddd;}
.gname{width:200px;display:inline-block;margin-left:30px;}
a:hover{text-decoration:none;color:black;}
</style>
<title>新增优惠活动</title>
</head>
<body>
<div class="pd-20">
	<form action="<%=path%>/backstage/coupon_act_addOrUpdate" method="post"  class="form form-horizontal" id="form-coupon_act_addOrUpdate">
		<input type="hidden" id="id" name="id" value='${t_coupon_act.id}' />

        <div class="row cl">
			<label class="form-label col-2">所属县市：</label>
			<div class="formControls col-3">
				<span class="select-box">
					<select id="city_id" name="city_id" class="select" datatype="n" nullmsg="请选择县市" >
						<c:forEach items="${citys}" var="city">
						<option value="${city.id}" <c:if test="${city.id==t_coupon_act.city_id}">selected</c:if> >${city.name}</option>
						</c:forEach>
					</select>
				</span>
			</div>
			<label class="form-label col-2">活动类型：</label>
			<div class="formControls col-3">
				<span class="select-box">
					<select id="act_type" name="act_type" class="select" datatype="n" nullmsg="请选择活动类型">
						<option value="1">邀请有奖</option>
					</select>
				</span>
			</div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-2">邀请人优惠券</label>
			<div class="formControls col-3">
				<a class="btn btn-primary radius" style="margin-bottom:5px;" onclick="addCoupon_invite();" href="javascript:;">
					<i class="Hui-iconfont">&#xe600;</i>添加</a>
			</div>
		</div>
		<div class="row cl">
			<div class="formControls col-10" id="addCoupon_invite">
				<c:forEach items="${t_coupon_act.inviteList}" var="act" varStatus="varStatus">
					<div class="rule-con" id="invite_${varStatus.count}">
					<br/><br/><br/>
					<img class="wimg" id="invite_simg${varStatus.count}" src="<%=imagePath%>${act.c_pname }">
					标题&nbsp;&nbsp;<input type="text"  name="invite_${varStatus.count}_c_titles" id="invite_${varStatus.count}_c_titles" value="${act.c_titles }" readonly class="input-text" style=" width:138px;">&nbsp;&nbsp;
					消费金额&nbsp;&nbsp;<input type="text" name="invite_${varStatus.count}_expenditure" id="invite_${varStatus.count}_expenditure" readonly value="${act.expenditure}" class="input-text" style=" width:70px;">&nbsp;&nbsp;
					优惠金额&nbsp;&nbsp;<input type="text" name="invite_${varStatus.count}_cashed" id="invite_${varStatus.count}_cashed" readonly value="${act.cashed}" class="input-text" style=" width:70px;">&nbsp;&nbsp;
					<input type="hidden" name="invite_${varStatus.count}_c_id" id="invite_${varStatus.count}_c_id" value="${act.c_id}"> 
					<a class="btn btn-primary radius" onclick="select_coupons(this,'invite_',${varStatus.count})" name="${varStatus.count}" href="javascript:;" title="选择优惠券">选择优惠券</a>
					<a class="btn btn-primary radius" onClick="act_disable('${varStatus.count}','invite')" href="javascript:;" title="删除">删除</a>
					<div class="bor"></div>
					</div>
				</c:forEach>
			</div>
		</div>
		
		<div class="row cl">
			<label class="form-label col-2">被邀请人优惠券</label>
			<div class="formControls col-3">
				<a class="btn btn-primary radius" style="margin-bottom:5px;" onclick="addCoupon_being_invite();" href="javascript:;">
					<i class="Hui-iconfont">&#xe600;</i>添加</a>
			</div>
		</div>
		<div class="row cl">
			<div class="formControls col-10" id="addCoupon_being_invite">
				<c:forEach items="${t_coupon_act.being_invitedList}" var="act" varStatus="varStatus">
					<div class="rule-con" id="being_invite_${varStatus.count}">
					<br/><br/><br/>
					<img class="wimg" id="being_invite_simg${varStatus.count}" src="<%=imagePath%>${act.c_pname }">
					标题&nbsp;&nbsp;<input type="text"  name="being_invite_${varStatus.count}_c_titles" id="being_invite_${varStatus.count}_c_titles" value="${act.c_titles }" readonly class="input-text" style=" width:138px;">&nbsp;&nbsp;
					消费金额&nbsp;&nbsp;<input type="text" name="being_invite_${varStatus.count}_expenditure" id="being_invite_${varStatus.count}_expenditure" readonly value="${act.expenditure}" class="input-text" style=" width:70px;">&nbsp;&nbsp;
					优惠金额&nbsp;&nbsp;<input type="text" name="being_invite_${varStatus.count}_cashed" id="being_invite_${varStatus.count}_cashed" readonly value="${act.cashed}" class="input-text" style=" width:70px;">&nbsp;&nbsp;
					<input type="hidden" name="being_invite_${varStatus.count}_c_id" id="being_invite_${varStatus.count}_c_id" value="${act.c_id}"> 
					<a class="btn btn-primary radius" onclick="select_coupons(this,'being_invite_',${varStatus.count})" name="${varStatus.count}" href="javascript:;" title="选择优惠券">选择优惠券</a>
					<a class="btn btn-primary radius" onClick="act_disable('${varStatus.count}','being_invite')" href="javascript:;" title="删除">删除</a>
					<div class="bor"></div>
					</div>
				</c:forEach>
			</div>
		</div>
		<input type="hidden" id="invite" name="invite" value="" />
		<input type="hidden" id="being_invited" name="being_invited" value="" />
		<br>
		</form>
		
		<div class="row cl">
			<div class="col-10 col-offset-2">
				<a href="javascript:void();" onclick="t_coupon_act_submit();" class="btn btn-primary radius">保存并提交</a>
				<button onClick="layer_close();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
			</div>
		</div>
		
</div>	
<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="lib/layer/2.1/layer.js"></script> 
<script type="text/javascript" src="lib/My97DatePicker/WdatePicker.js"></script> 
<script type="text/javascript" src="lib/icheck/jquery.icheck.min.js"></script> 
<script type="text/javascript" src="lib/Validform/5.3.2/Validform.min.js"></script> 
<script type="text/javascript" src="lib/webuploader/0.1.5/webuploader.min.js"></script> 
<script type="text/javascript" src="lib/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="lib/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="lib/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript" src="js/H-ui.js"></script> 
<script type="text/javascript" src="js/H-ui.admin.js"></script> 
<script type="text/javascript" src="js/jquery.form.js"></script> 
<script type="text/javascript">

	$(function(){
		$('.skin-minimal input').iCheck({
			checkboxClass: 'icheckbox-blue',
			radioClass: 'iradio-blue',
			increaseArea: '20%'
		});
	});
	
	var inviteSize = ${inviteSize};
	function addCoupon_invite(){
		var $aCoupon = $('<div class="rule-con" id="invite_'+(++inviteSize)+'"> <br/><br/><br/> <img class="wimg" id="invite_simg'+ (inviteSize) +'" src="">'
			+ '标题：<input type="text" name="invite_'+ (inviteSize) +'_c_titles" id="invite_'+ (inviteSize) +'_c_titles" value="" readonly class="input-text" style=" width:138px;">&nbsp;&nbsp;'
			+ '消费金额：<input type="text" name="invite_'+ (inviteSize) +'_expenditure" id="invite_'+ (inviteSize) +'_expenditure" value="" readonly class="input-text" style=" width:70px;">&nbsp;&nbsp;'
			+ '优惠金额：<input type="text" name="invite_'+ (inviteSize) +'_cashed" id="invite_'+ (inviteSize) +'_cashed" value="" readonly class="input-text" style=" width:70px;">&nbsp;&nbsp;'
			+ '<input type="hidden" name="invite_'+ (inviteSize) +'_c_id" id="invite_'+ (inviteSize) +'_c_id" value="">'
			+ '<a class="btn btn-primary radius" onclick="select_coupons(this,\'invite_\','+(inviteSize)+')" name="invite_'+ (inviteSize)+'" href="javascript:;" title="选择优惠券">选择优惠券</a>'
			+ '<a class="btn btn-primary radius" onClick="act_disable('+(inviteSize)+',\'invite\')" href="javascript:;" title="删除">删除</a>'
			+ '<div class="bor"></div>'
			+ '</div>');
		$("#addCoupon_invite").append($aCoupon);
	}
	
	var being_inviteSize = ${being_inviteSize};
	function addCoupon_being_invite(){
		var $aCoupon = $('<div class="rule-con" id="being_invite_'+ (++being_inviteSize) +'"> <br/><br/><br/> <img class="wimg" id="being_invite_simg'+ (being_inviteSize) +'" src="">'
			+ '标题：<input type="text" name="being_invite_'+ (being_inviteSize) +'_c_titles" id="being_invite_'+ (being_inviteSize) +'_c_titles" value="" readonly class="input-text" style=" width:138px;">&nbsp;&nbsp;'
			+ '消费金额：<input type="text" name="being_invite_'+ (being_inviteSize) +'_expenditure" id="being_invite_'+ (being_inviteSize) +'_expenditure" value="" readonly class="input-text" style=" width:70px;">&nbsp;&nbsp;'
			+ '优惠金额：<input type="text" name="being_invite_'+ (being_inviteSize) +'_cashed" id="being_invite_'+ (being_inviteSize) +'_cashed" value="" readonly class="input-text" style=" width:70px;">&nbsp;&nbsp;'
			+ '<input type="hidden" name="being_invite_'+ (being_inviteSize) +'_c_id" id="being_invite_'+ (being_inviteSize) +'_c_id" value="">'
			+ '<a class="btn btn-primary radius" onclick="select_coupons(this,\'being_invite_\','+(being_inviteSize)+')" name="invite_'+ (being_inviteSize)+'" href="javascript:;" title="选择优惠券">选择优惠券</a>'
			+ '<a class="btn btn-primary radius" onClick="act_disable('+(being_inviteSize)+',\'being_invite\')" href="javascript:;" title="删除">删除</a>'
			+ '<div class="bor"></div>'
			+ '</div>');
		$("#addCoupon_being_invite").append($aCoupon);
	}
	
	/* 删除优惠券 */
	function act_disable(num,div_name){
		layer.confirm('确认删除？', {
			btn: ['确认','取消'], 
			shade: false
		},
		function(){
			$("#"+div_name+"_"+num).remove();
			layer.msg('已删除！', {icon:5,time:1000});
		},
		function(){
			layer.msg('未删除！', {icon:5,time:1000});
		});	
	}
	
	function select_coupons(obj,div_name,num){
		var city_id = $("#city_id").val();
		var act_type = $("#act_type").val();
		if(act_type=='1'){//推荐有奖
			act_type='2';
		}
		var data = "city_id="+city_id+"&act_type="+act_type+"&div_name="+div_name+"&num="+num;
		layer_show('选择优惠券', '<%=path%>/backstage/select_coupons?'+data, 800, 500);
	}
	
	function show1(responseText, statusText, xhr, $form){
		var index = parent.layer.getFrameIndex(window.name);
		parent.$('.btn-refresh').click();
		parent.layer.close(index);
	}
	
	function t_coupon_act_submit(){
		//将邀请优惠券、被邀请优惠券组合成String
		var coupons = $("div[id^='invite_']");
		var invite = "";
		var being_invited = "";
		for (var i = 0; i < coupons.length; i++){
			invite += $(coupons[i]).find("input[id$='_c_id']").val()+",";
			//var being_invited_id = $(coupons[i]).find("input[id^='being_invite_']").val();
		}
		coupons = $("div[id^='being_invite_']");
		for (var i = 0; i < coupons.length; i++){
			being_invited += $(coupons[i]).find("input[id$='_c_id']").val()+",";
			//var being_invited_id = $(coupons[i]).find("input[id^='being_invite_']").val();
		}
		
		$("#invite").val(invite);
		$("#being_invited").val(being_invited);
		
		var options1 = {success:show1,url:'<%=path%>/backstage/coupon_act_addOrUpdate'};
		$("#form-coupon_act_addOrUpdate").ajaxSubmit({
            type: "post",
            url: '<%=path%>/backstage/coupon_act_addOrUpdate',
            dataType: "json",
            data: { "filename": $("#fuldDoc").val() },
            success: function (data) {
                if (data.error == "0000"){
                	//alert(data.information);
                	parent.layer.alert(data.information, {icon:6});
                	var index = parent.layer.getFrameIndex(window.name);
            		parent.$('.btn-refresh').click();
            		parent.layer.close(index);
                }else{
                	layer.msg(data.information, {icon:5,time:1000});
                }
            },
            error: function () {
                layer.msg("系统出现错误，请联系管理员", {icon:5,time:1000});
            }
        });
	}

</script>
</body>
</html>

